package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Problem;
import cn.wolfcode.luowowo.article.mapper.ProblemMapper;
import cn.wolfcode.luowowo.article.query.ProblemCommendQuery;
import cn.wolfcode.luowowo.article.service.IProblemService;
import cn.wolfcode.luowowo.common.exception.LogicException;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
public class ProblemServiceImpl implements IProblemService {
    @Autowired
    private ProblemMapper problemMapper;

    @Override
    public void savaOrUpdate(Problem p) {
        if(p!=null){
            p.setCreateTime(new Date());
            problemMapper.insert(p);
        }else {
            throw new LogicException("对象不能为空");
        }
    }

    @Override
    public PageInfo query(ProblemCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"createTime desc");
        return new PageInfo(problemMapper.seleceForList(qo));
    }

    @Override
    public Problem selectByPrimaryKey(Long id) {
        return problemMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateReplynum(Long probId,Long count) {
        problemMapper.updateReplynum(probId,count);
    }

}
